package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.damgesource.SkillDamageSource;
import net.xxcxcxcx.xc_enhancedmob.math.IntToRoman;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

import java.util.LinkedList;
import java.util.Queue;

public class CapriceSkill extends BaseSkill {

    public Queue<DamageSource> damageSources = new LinkedList<>();

    public CapriceSkill(int level) {
        super(level);
    }

    public CapriceSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public CapriceSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return "善变技能，会保存level*4数量的之前受到伤害，之后受到伤害每不重复一次-5%。";
    }

    @Override
    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (source instanceof SkillDamageSource source1 && source1.getPassSkill()) return true;
        Ref<Integer> count = new Ref<>(0);
        damageSources.forEach(damageSource -> {
            if (damageSource.name.compareTo(source.name) != 0) {
                count.setValue(count.getValue() + 1);
            }
        });
        amount.setValue(amount.getValue() * IntToRoman.pow(0.95f, count.getValue()));
        damageSources.add(source);
        if (damageSources.size() > getSkillLevel() * 4) {
            damageSources.poll();
        }
        return true;
    }


}
